<div class="panel panel-default search-panel">
    <div class="panel-body">
        <div class="pull-left">
            <form class="form-inline">
                <div class="form-group">
                    <label class="sr-only" for="query_name">Remark</label>
                    <input type="text" ng-model="query_name" id="query_name" class="form-control" placeholder="名称" />
                </div>
                <div class="form-group">
                    <select ng-model="query_status" class="form-control">
                        <option value="">选择状态</option>
                        <option value="{{ STATAUS_ENABLED }}">运行中</option>
                        <option value="{{ STATAUS_DISABLED }}">停止</option>
                    </select>
                </div>
                <div class="form-group">
                    <label class="sr-only" for="query_remark">Remark</label>
                    <input type="text" ng-model="query_remark" id="query_remark" class="form-control" placeholder="描述" />
                </div>
                <button type="submit" class="btn btn-default" ng-click="query()">查找</button>
            </form>
        </div>
        <div class="pull-right">
            <button type="button" class="btn" id="syncBtn" ng-click="sync()" ng-class="{'btn-default':syncing, 'btn-primary':!syncing}" ng-disabled="syncing">
                同步调度
                <span class="glyphicon glyphicon-arrow-up" ng-if="!syncing"></span>
                <span class="glyphicon glyphicon-refresh" ng-if="syncing"></span>
            </button>
            <button type="button" class="btn btn-primary" ng-click="edit()">
                创建调度
                <span class="glyphicon glyphicon-plus-sign"></span>
            </button>
        </div>
        <div class="clearfix"></div>
    </div>
</div>
<table class="table table-striped table-bordered table-hover">
    <tr>
        <th>名称</th>
        <th>表达式</th>
        <th>状态</th>
        <th>调用方法</th>
        <th>执行次数</th>
        <th>执行时间</th>
        <th>描述</th>
        <th>操作</th>
    </tr>
    <tr ng-repeat="scheduler in paged.list">
        <td>{{ scheduler.name }}</td>
        <td>{{ scheduler.expression }}</td>
        <td>
            <span ng-class="{'label': true, 'label-success': (scheduler.status == STATAUS_ENABLED), 'label-danger': scheduler.status == STATAUS_DISABLED}">
                {{ (scheduler.status == STATAUS_ENABLED) ? '运行中' : '停止' }}
            </span>
        </td>
        <td>{{ scheduler.bean }}.{{ scheduler.method }}</td>
        <td>{{ scheduler.execCount }}</td>
        <td>{{ (scheduler.execTime / 1000) | number:4 }}</td>
        <td>{{ scheduler.remark }}</td>
        <td style="width: 300px;">
            <button type="button" class="btn btn-primary" ng-click="edit(scheduler)">编辑</button>
            <button type="button" class="btn" ng-click="run(scheduler.id)" ng-class="{'btn-primary':!running[scheduler.id],'btn-default':running[scheduler.id]}" ng-if="scheduler.status == STATAUS_ENABLED" ng-disabled="running[scheduler.id]">
                运行
            </button>
            <button type="button" class="btn btn-primary" ng-click="start(scheduler.id)" ng-if="scheduler.status == STATAUS_DISABLED">启动</button>
            <button type="button" class="btn btn-warning" ng-click="stop(scheduler.id)" ng-if="scheduler.status == STATAUS_ENABLED">暂停</button>
            <button type="button" class="btn btn-danger" ng-click="confirmRemove(scheduler.id)">删除</button>
        </td>
    </tr>
</table>
<div>
    <div ng-include="'app/common/view/paged.html'"></div>
</div>

<!-- edit dialog -->
<div class="modal fade" id="editDialog" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">{{ editDialogTitle }}</h4>
            </div>
            <div class="modal-body">
                <div id="editErrorMsg" class="alert alert-danger hide"></div>
                <form class="form-horizontal" role="form" id="editForm">
                    <div class="form-group">
                        <label for="save_name" class="col-sm-2 control-label">Bean</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="save_name" ng-model="save_name" placeholder="名称" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="save_bean" class="col-sm-2 control-label">Bean</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="save_bean" ng-model="save_bean" placeholder="Spring Bean Class" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="save_method" class="col-sm-2 control-label">Method</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="save_method" ng-model="save_method" placeholder="Method"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="save_expression" class="col-sm-2 control-label">表达式</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="save_expression" ng-model="save_expression" placeholder="Quartz表达式"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="save_remark" class="col-sm-2 control-label">描述</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="save_remark" ng-model="save_remark" placeholder="描述"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" ng-click="save()">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

<!-- delete dialog -->
<div class="modal fade" id="removeDialog" tabindex="-1">
    <input type="hidden" id="removeId" ng-model="removeId" />
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">删除确认</h4>
            </div>
            <div class="modal-body">
                <div class="alert alert-warning">您确认要删除吗，删除调度可能会导致程序异常</div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" ng-click="remove()">确认删除</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>